<!DOCTYPE html>
<html lang="en">
<head>
<#include "/common/head.ftl"/>
<script type="text/javascript">
	$(document).ready(function() {

	});
	function submitForm() {
		var mob = /^1[3|4|5|6|7|8|9][0-9]\d{4,8}$/;
		var userAccount = $("#userAccount").val();
		var userPassword = $("#userPassword").val();
		var userAgainPassword = $("#userAgainPassword").val();
		var userValidateCode = $("#userValidateCode").val();
		if (userAccount) {
			if (!mob.exec(userAccount)) {
				$("#validInfo").html("手机号码格式不对！");
				$("#userAccount").attr('value', '');
				$("#userAccount").focus();
				return false;
			} else {
				if (userPassword) {
					if ((userPassword.length < 6) || (userPassword.length > 20)) {
						$("#validInfo").html("密码长度应为6-20位数！");
						$("#userPassword").focus();
					} else {
						if (userPassword != userAgainPassword) {
							$("#validInfo").html("两次密码输入不一致！");
							$("#userPassword").attr('value', '');
							$("#userAgainPassword").attr('value', '');
							$("#userPassword").focus();
						} else {
							var hasChk = $('#xieyiCheckbox').is(':checked');
							if (hasChk) {
								if (userValidateCode) {
									$("#validInfo").html("");
									$.post($("#form1").attr("action"), $(
											"#form1").serialize(), function(
											data) {
										var result = $.parseJSON(data);
										if (result.code == 0) {
											window.location.href = result.url;
										} else {
											$("#validInfo")
													.html(result.message);
										}
									});
								} else {
									$("#validInfo").html("请输入验证码！");
									$("#userValidateCode").focus();
								}
							} else {
								$("#validInfo").html("请阅读并同意学而阅读服务协议！");
							}

						}
					}
				} else {
					$("#validInfo").html("请输入密码！");
					$("#userPassword").focus();
				}
			}
		} else {
			$("#validInfo").html("请输入手机号码！");
			$("#userAccount").focus();
		}

	}
	function sendSMS() {
		var mob = /^1[3|4|5|6|7|8|9][0-9]\d{4,8}$/;
		var userAccount = $("#userAccount").val();
		if (userAccount) {
			if (!mob.exec(userAccount)) {
				$("#validInfo").html("手机号码格式不对！");
				$("#userAccount").attr('value', '');
				$("#userAccount").focus();
				return false;
			} else {
				$("#validInfo").html("");
				$.post("${path}/user/sendSMS", "userAccount=" + userAccount,
						function(data) {
							var result = $.parseJSON(data);
							if (result.code == 0) {
								$("#send").attr("href", "javascript:void( );");
								countdownSend(60);
							} else {
								$("#validInfo").html(result.message);
							}
						});
			}
		} else {
			$("#validInfo").html("请输入手机号码！");
			$("#userAccount").focus();
		}
	}
	function countdownSend(id) {
		id = id - 1;
		if (id > 0) {
			$("#send").html(id);
			setTimeout("countdownSend(" + id + ")", 1000);
		} else {
			$("#send").html("重新获取验证码");
			$("#send").attr("href", "javascript:sendSMS();");
			bindSms();
		}
	}
</script>

</head>
<body>
	<#include "/common/header.ftl"/>
	<!-- 主内容 -->
	<div class="wrap">
		<div class="container">
			<div class="container-bd">
				<div class="register">
					<form id="form1" name="form1" action="${path}/user/register"
						method="post">
						<div class="reg-head">
							<div class="reg-head-title f42">手机注册</div>
							<div class="tip f36">输入手机号，获取验证码，输入验证码正确后，设置账号密码，完成注册</div>
						</div>
						<div class="reg-form">
							<div class="line">
								<div class="input">
									<input type="text" name="userAccount" class="username"
										id="userAccount" placeholder="填写手机号码">
								</div>
							</div>
							<div class="line">
								<div class="input input-exp fl">
									<input type="text" name="userValidateCode"
										id="userValidateCode" class="vcode" placeholder="填写验证码" />
								</div>
								<a class="get-vcode f40 cfff tc dlb fr"
									href="javascript:sendSMS();" id="send">获取验证码</a>
							</div>
							<div class="line">
								<div class="input">
									<input type="password" name="userPassword" id="userPassword"
										class="psd" placeholder="填写密码" />
								</div>
							</div>
							<div class="line">
								<div class="input">
									<input type="password" name="userAgainPassword"
										id="userAgainPassword" class="psd-again" placeholder="请再次输入密码" />
								</div>
							</div>
							<div class="line read">
								<input type="checkbox" id="xieyiCheckbox">
							<!--<label class="f30">我已阅读<a href="${path}/user/protocol">“学而阅读服务协议”</a></label>-->
								<label class="f30">我已阅读<a href="#">“学而阅读服务协议”</a></label>
							</div>
							<div class="error-info">
								<span id="validInfo"></span>
							</div>
							<div class="btn-reg">
								<input type="button" onclick="submitForm();" value="点击注册" />
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	<#include "/common/footer.ftl"/>
</body>
</html>